﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

using EHTSaleManager.Code.DAL;
using EHTSaleManager.Code.Entity;

namespace EHTSaleManager.Code.BLL
{
    public class AccountBalanceProvider
    {
        public static Boolean UpdateAccountBalanceByCustomerID(string CustomerID, float AmountOfMoney, int SeviceLevelID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_UpdateAccountBalanceByCustomerID";
            command.CommandType = CommandType.StoredProcedure;
            

            command.Parameters.Add(new SqlParameter("@CustomerID", CustomerID));
            command.Parameters.Add(new SqlParameter("@AmountOfMoney", AmountOfMoney));
            command.Parameters.Add(new SqlParameter("@SeviceLevelID", SeviceLevelID));

    
            DataProvider.ExecuteNoneQuery(command);

            return true;
        }

        // Lay Account Current Balance by CustomerID
        public static CurrentBalance GetCurrentBalanceByCustomerID(string CustomerID)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_GetCurrentBalanceByCustomerID";
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@CustomerID", CustomerID));

            DataSet ds = DataProvider.ExecuteDataSet(command);
            CurrentBalance theCurrentBalace = null;

            if (ds.Tables[0].Rows.Count > 0)
            {
                theCurrentBalace = new CurrentBalance();
                theCurrentBalace.CurentID = Int32.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
                theCurrentBalace.CustomerID = ds.Tables[0].Rows[0]["CustomerID"].ToString();
                theCurrentBalace.TotalAmount = float.Parse(ds.Tables[0].Rows[0]["TotalAmount"].ToString());
                theCurrentBalace.Month = Int32.Parse(ds.Tables[0].Rows[0]["Month"].ToString());
                theCurrentBalace.Year = Int32.Parse(ds.Tables[0].Rows[0]["Year"].ToString());
            }

            return theCurrentBalace;
        }

        // update Account CurrentBalance khi khach hang xoa don dat hang
        public static Boolean UpdateCurrentBalance(string CustomerID, float TotalAmount)
        {
            SqlCommand command = new SqlCommand();
            command.CommandText = "proc_IUCurrentBalance";
            command.CommandType = CommandType.StoredProcedure;
                      

            command.Parameters.Add(new SqlParameter("@CustomerID", CustomerID));
            command.Parameters.Add(new SqlParameter("@TotalAmount", TotalAmount));           

            DataProvider.ExecuteNoneQuery(command);

            return true;
        }        

    }
}